import { Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";

@Entity("character_attribute_points")
@ManualTimestamp()
export class CharacterAttributePointsEntity {
  @PrimaryGeneratedColumn({ comment: "主键ID" })
  id!: number;

  @Column("int", { name: "characterId", comment: "角色ID" })
  characterId!: number;

  @Column("int", { default: 0, comment: "力量属性点(ap)" })
  strength!: number;

  @Column("int", { default: 0, comment: "体质属性点(hp)" })
  constitution!: number;

  @Column("int", { default: 0, comment: "智力属性点(mp)" })
  intelligence!: number;

  @Column("int", { default: 0, comment: "敏捷属性点(sp)" })
  agility!: number;

  @Column("int", { default: 0, comment: "剩余可分配属性点" })
  availablePoints!: number;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", nullable: true, comment: "更新时间" })
  updated_at!: Date | null;

  // 关联关系
  @OneToOne(() => CharacterEntity, (character) => character.attributePoints)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;
}
